package com.data.permission.test.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.data.permission.annotation.DataAuth;
import com.data.permission.rule.DataRuleInfoComponent;
import com.data.permission.test.entity.RuleTest;
import com.data.permission.test.service.IRuleTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangbo
 * @since 2019-11-04
 */
@RestController
@RequestMapping("/test/rule-test")
public class RuleTestController {

    @Autowired
    private IRuleTestService ruleTestService;

    @Autowired
    private DataRuleInfoComponent dataRuleInfoComponent;

    @GetMapping("/test1")
    @DataAuth(ruleCode = "test1")
    public Object test1() {
        List<RuleTest> list = ruleTestService.list(new QueryWrapper<>());
        return list;
    }

    @GetMapping("/test2")
    @DataAuth(ruleCode = "test2")
    public Object test2() {
        List<RuleTest> list = ruleTestService.list(new QueryWrapper<>());
        return list;
    }

    @GetMapping("/test3")
    @DataAuth(ruleCode = "test3")
    public Object test3(RuleTest ruleTest) {
        List<RuleTest> list = ruleTestService.list(new QueryWrapper<>());
        return list;
    }

    @GetMapping("/test4")
    public Object test4() {
        List<RuleTest> list = ruleTestService.list(new QueryWrapper<>());
        return list;
    }

    @GetMapping("/save")
    public Object save() {
        RuleTest ruleTest = new RuleTest();
        ruleTest.setName("test");
        ruleTest.setCreateUser("zhangbo");
        ruleTest.setUpdateUser("zhangbo");
        ruleTestService.save(ruleTest);
        return "success";
    }

    @GetMapping("/delete")
    public Object delete(int id) {
        ruleTestService.removeById(id);
        return "success";
    }
}
